﻿<h1>ReadOnly GridView Control Example</h1>
This example explains how to create a window with a read-only GridView control, bind to the data and show on the screen. <br>GridView is read-only because we use <i>gridviewstatictextcolumn</i> column types.<br>
<button id="ReadOnlyGridViewExample" class="try-example-button">Try Example</button>
<h2>UI Model</h2>
<div style="color:Black;background-color:White;"><pre>{
    <span style="color:#A31515;">"windows"</span>: [
        {
            <span style="color:#A31515;">"name"</span>: <span style="color:#A31515;">"ReadOnlyGridViewExample"</span>,
            <span style="color:#A31515;">"title"</span>: <span style="color:#A31515;">"Read-Only GridView Example"</span>,
            <span style="color:#A31515;">"left"</span>: 500,
            <span style="color:#A31515;">"top"</span>: 100,
            <span style="color:#A31515;">"width"</span>: 500,
            <span style="color:#A31515;">"height"</span>: 300,
            <span style="color:#A31515;">"controls"</span>: [
                <b>{
                    <span style="color:#A31515;">"name"</span>: <span style="color:#A31515;">"managersGrid"</span>,
                    <span style="color:#A31515;">"type"</span>: <span style="color:#A31515;">"gridview"</span>,
                    <span style="color:#A31515;">"bindsTo"</span>: <span style="color:#A31515;">"list"</span>,
                    <span style="color:#A31515;">"canUserAddRows"</span>: <span style="color:Blue;">false</span>,
                    <span style="color:#A31515;">"columns"</span>: [
                        {
                            <span style="color:#A31515;">"type"</span>: <span style="color:#A31515;">"gridviewstatictextcolumn"</span>,
                            <span style="color:#A31515;">"name"</span>: <span style="color:#A31515;">"title"</span>,
                            <span style="color:#A31515;">"label"</span>: <span style="color:#A31515;">"Title"</span>,
                            <span style="color:#A31515;">"width"</span>: 170,
                            <span style="color:#A31515;">"bindsTo"</span>: <span style="color:#A31515;">"title"</span>
                        },
                        {
                            <span style="color:#A31515;">"type"</span>: <span style="color:#A31515;">"gridviewstatictextcolumn"</span>,
                            <span style="color:#A31515;">"name"</span>: <span style="color:#A31515;">"name"</span>,
                            <span style="color:#A31515;">"label"</span>: <span style="color:#A31515;">"Name"</span>,
                            <span style="color:#A31515;">"width"</span>: 280,
                            <span style="color:#A31515;">"bindsTo"</span>: <span style="color:#A31515;">"name"</span>
                        }
                    ]
                }</b>,
                {
                    <span style="color:#A31515;">"name"</span>: <span style="color:#A31515;">"OKButton"</span>,
                    <span style="color:#A31515;">"type"</span>: <span style="color:#A31515;">"button"</span>,
                    <span style="color:#A31515;">"text"</span>: <span style="color:#A31515;">"OK"</span>,
                    <span style="color:#A31515;">"isDialogButton"</span>: <span style="color:Blue;">true</span>,
                    <span style="color:#A31515;">"dialogResult"</span>: <span style="color:#A31515;">"OK"</span>
                },
                {
                    <span style="color:#A31515;">"name"</span>: <span style="color:#A31515;">"CancelButton"</span>,
                    <span style="color:#A31515;">"type"</span>: <span style="color:#A31515;">"button"</span>,
                    <span style="color:#A31515;">"text"</span>: <span style="color:#A31515;">"Cancel"</span>,
                    <span style="color:#A31515;">"isDialogButton"</span>: <span style="color:Blue;">true</span>,
                    <span style="color:#A31515;">"dialogResult"</span>: <span style="color:#A31515;">"Cancel"</span>
                }
            ]
        }
    ]
}
</pre></div>
<h2>Data Model</h2>
<div style="color:Black;background-color:White;"><pre><span style="color:Blue;">var</span> teamManagement = {
	list: [
		{
			id: 7,
			title: <span style="color:#A31515;">"Manager"</span>,
			name: <span style="color:#A31515;">"Fiorello Lombardi"</span>,
		},
		{
			id: 8,
			title: <span style="color:#A31515;">"Goalkeeping Coach"</span>,
			name: <span style="color:#A31515;">"Armando Arcuri"</span>,
		},
		{
			id: 9,
			title: <span style="color:#A31515;">"Assistant Manager"</span>,
			name: <span style="color:#A31515;">"Alessio Ferri"</span>,
		},
		{
			id: 10,
			title: <span style="color:#A31515;">"First-team Coach"</span>,
			name: <span style="color:#A31515;">"Giuseppe Milani"</span>,
		}
	]
};
</pre></div>
<h2>Code</h2>
<div style="color:Black;background-color:White;"><pre><span style="color:Blue;">var</span> exampleWindow = redui.createNewWindow(<span style="color:#A31515;">"ReadOnlyGridViewExample"</span>);
exampleWindow.bind(teamManagement);

exampleWindow.closed(<span style="color:Blue;">function</span> (target, dialogResult) {
	<span style="color:Blue;">if</span> (dialogResult === <span style="color:#A31515;">"OK"</span>) {
		<span style="color:Blue;">var</span> currentRow = exampleWindow.managersGrid.currentRow;
		<span style="color:Blue;">if</span> (currentRow) {
			<span style="color:Blue;">var</span> object = currentRow.bindingContext;
			alert(<span style="color:#A31515;">"Selected row: "</span> + JSON.stringify(object));
		} <span style="color:Blue;">else</span> {
			alert(<span style="color:#A31515;">"Row was not selected."</span>);
		}
	}
});

exampleWindow.show();
</pre>